/**
 * 基础菜单 商品管理
 */
<template>
  <div>
    <!-- 面包屑导航 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>投诉管理</el-breadcrumb-item>
    </el-breadcrumb>
    <!-- 搜索筛选 -->
    <el-form :inline="true" :model="formInline" class="user-search">
       <el-form-item label="搜索：">
        <el-input size="small" v-model="formInline.businessId" placeholder="输入投诉编号" clearable></el-input>
      </el-form-item>
      <el-form-item >
         <el-select size="small" v-model="formInline.businessType" placeholder="请选择投诉类型" clearable>
          <el-option v-for="type in complaintType" :label="type.key" :value="type.value" :key="type.value"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="">
        <el-input
          size="small"
          v-model="formInline.content"
          placeholder="输入投诉内容"
          clearable
        ></el-input>
      </el-form-item>
      <el-form-item>
        <el-select size="small" v-model="formInline.isHandle" placeholder="请选择投诉处理情况" clearable>
          <el-option v-for="type in payway" :label="type.key" :value="type.value" :key="type.value"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="">
        <el-input
          size="small"
          v-model="formInline.orderNo"
          placeholder="输入投诉订单号"
          clearable
        ></el-input>
      </el-form-item>
      <el-form-item>
        <el-button
          size="small"
          type="primary"
          icon="el-icon-search"
          @click="search"
          >搜索</el-button
        >
        <el-button size="small"
          type="primary"
          icon="el-icon-search"
          @click="add">添加投诉</el-button>
        <el-button size="small"
        type="primary"
        icon="el-icon-search"
        @click="manage">管理我的用户投诉</el-button>
        <!-- <el-button
          size="small"
          type="primary"
          icon="el-icon-plus"
          @click="handleEdit()"
          >新增</el-button
        > -->
      </el-form-item>
    </el-form>
    <!--列表-->
    <el-table
      size="small"
      :data="listData"
      highlight-current-row
      v-loading="loading"
      border
      element-loading-text="拼命加载中"
      style="width: 100%"
    >
      <el-table-column align="center" type="selection" width="60">
      </el-table-column>
      <el-table-column sortable prop="businessId" label="ID" width="100">
      </el-table-column>
      <el-table-column sortable prop="orderNo" label="订单号" width="100">
      </el-table-column>
      <el-table-column sortable prop="businessType" label="投诉类型" width="100">
        <template slot-scope="scope" v-if="complaintType[scope.row.businessType]">
          <span>{{complaintType[scope.row.businessType].key}}</span>
        </template>
      </el-table-column>
      <el-table-column sortable prop="content" label="投诉内容" width="150">
      </el-table-column>
        <el-table-column sortable prop="createTime" label="投诉时间" width="100">
      </el-table-column>
      
      <el-table-column sortable prop="status" label="状态" width="100">
        <template slot-scope="scope">
          <div>{{ scope.row.isHandle === 2 ? "已处理" : "未处理" }}</div>
        </template>
      </el-table-column>

      <el-table-column align="center" label="操作" min-width="100">
        <template slot-scope="scope">
          <el-button size="mini" @click="handleEdit(scope.$index, scope.row)"
            >详情</el-button
          >
          <el-button
            size="mini"
            type="danger"
            @click="deleteUser(scope.$index, scope.row)" v-if="scope.row.isHandle === 2"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页组件 -->
    <Pagination
      v-bind:child-msg="pageparm"
      @callFather="callFather"
    ></Pagination>
    <!-- 编辑界面 -->
    <el-dialog
      :title="title"
      :visible.sync="editFormVisible"
      width="40%"
      @click="closeDialog"
    >
      <el-form
        label-width="120px"
        :model="editForm"
        :rules="rules"
        ref="editForm"
      >
    
        <el-form-item label="投诉类型" prop="complaintType" v-if="complaintType[editForm.businessType]">
          <el-input
            size="small"
            v-model="complaintType[editForm.businessType].key"
            auto-complete="off"
           :value="complaintType[editForm.businessType].key" disabled 
          ></el-input>
        </el-form-item>
        <el-form-item label="投诉内容" prop="content">
          <el-input
            size="small"
            v-model="editForm.content"
            auto-complete="off"
           :value="editForm.content" disabled 
          ></el-input>
        </el-form-item>

        <el-form-item label="投诉图片" prop="url"  >
            <div v-for="(item,index) in editForm.url" v-bind:key="index"> 
                  <el-image :src="item"></el-image>
            </div>
            
        </el-form-item>

        <el-form-item label="回复"  v-if="editForm.handleContent" >
            <el-input
            size="small"
           disabled 
            v-model="editForm.handleContent"
            placeholder="请输入你要回复用户的内容"
            ></el-input>
        </el-form-item>
        <el-form-item label="回复人" v-if="editForm.handlePeople">
            <el-input
            size="small"
            v-model="editForm.handlePeople"
           disabled 
            ></el-input>
        </el-form-item>
        <el-form-item label="回复时间" v-if="editForm.handleTime" >
            <el-input
            size="small"
            v-model="editForm.handleTime"
           disabled 
            ></el-input>
        </el-form-item>

      </el-form>
      <div slot="footer" class="dialog-footer"  >
        <el-button
        
          size="small"
          type="primary"
          :loading="loading"
          class="title"
          @click="submitForm('editForm')"
          >确定</el-button
        >
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { deptList, deptSave, deptDelete } from "../../api/userMG";
import Pagination from "../../components/Pagination";
export default {
  data() {
    return {
        url:"http://localhost:1011/business/",
      nshow: true, //switch开启
      fshow: false, //switch关闭
      loading: false, //是显示加载
      editFormVisible: false, //控制编辑页面显示与隐藏
      title: "添加",
      editForm: [
        // id: null,
        // account: "",
        // password: "",
        // status: "y",
        //token: localStorage.getItem("logintoken"),
      
      ],
      
      // rules表单验证
      rules: {
        deptName: [
          { required: true, message: "请输入部门名称", trigger: "blur" },
        ],
        deptNo: [
          { required: true, message: "请输入部门代码", trigger: "blur" },
        ],
      },
      formInline: {
        //设置加载初始页
        page: 1,
        //设置加载初始条数
        limit: 5,
        businessType:0,
        content:"",
        businessId :'',
        isHandle:0,
        orderNo:'',
      },
      complaintType:[
        { key: '请选择投诉类型', value: 0 },

        ]
            
      ,
       payway: [
        { key: '请选择投诉处理情况', value: 0 },
        { key: '未处理', value: 1 },
        { key: '已处理', value: 2 },
       
      ],
      // 删除部门
      seletedata: {
        ids: "",
        token: localStorage.getItem("logintoken"),
      },
      userparm: [], //搜索权限
      listData: [], //用户数据
      // 分页参数
      pageparm: {
        currentPage: 1,
        pageSize: 10,
        total: 10,
      },
    };
  },
  // 注册组件
  components: {
    Pagination,
  },
  /**
   * 数据发生改变
   */

  /**
   * 创建完毕
   */
  created() {
    this.getdata(this.formInline);
    this.getType();
  },

  /**
   * 里面的方法只有被调用才会执行
   */
  methods: {
    //获取投诉类型列表
    getType(){
      this.$axios.get(this.url+"findType").then(res=>{
        let data = res.data.data
        if(res.data.code==200){
         for(let i in data){
           this.complaintType.push({"key":data[i].name,"value":data[i].type})
         }
        }
      }).catch()
    },
    // 获取列表yyyyyy
    getdata(parameter) {
      this.loading = true;
      this.$axios
        .get(
          this.url+"findAll/"+this.formInline.page+"/"+this.formInline.limit
            
        )
        .then((response) => {
         
          if(response.data.code == 200){
               this.listData = response.data.data.list;
              this.pageparm.total = response.data.data.total;
          }else {
              
              this.listData = response.data.data.list;
              this.pageparm.total = response.data.data.total;
              this.$message({
              type: 'info',
              message: response.data.msg
              
             })
            //  this.$store.commit('login', 'true')
            // this.$router.push({ path: '/login' })
          }
         
        })
        .catch(function (error) {
          console.log(error);
         
         
        });
      //设为false 页面不在现在正在加载中
      this.loading = false;

      this.pageparm.currentPage = this.formInline.page;
      this.pageparm.pageSize = this.formInline.limit;

    },
    // 分页插件事件
    callFather(parm) {
      this.formInline.page = parm.currentPage;
      this.formInline.limit = parm.pageSize;
      this.getdata(this.formInline);
    },
    // 搜索事件
    search() {
      this.findByCondition(this.formInline);
      //展示页面在1第一页
      this.formInline.page = 1;
      //展示分页下标在第一页
      this.pageparm.currentPage = 1;
    },
    findByCondition(formInline){
        this.$axios.post(this.url+"findByCondition/"+this.formInline.page+"/"+this.formInline.limit,formInline).then(res=>{
          let data = res.data.data
          console.log(data);
          if(res.data.code==200){
            this.listData = data.list
            this.pageparm.total = res.data.data.total;
           
          }else {
              this.listData = res.data.data.list;
              this.pageparm.total = res.data.data.total;
              this.$message({
              type: 'info',
              message: res.data.msg
              
             })
            //  this.$store.commit('login', 'true')
            // this.$router.push({ path: '/login' })
          }
        }).catch()
    },
    //显示编辑界面
    handleEdit: function (index, row) {
       
        console.log(row);
      
      
       
      //editFormVisble 表示某个弹窗的隐藏或者显示
        this.editFormVisible = true;
        this.title="详情"
        
        let url = row.url
        if(typeof url==="string"){
          row.url=url.split(",")
        }
        
        this.editForm= row
       
        

    },
    // 编辑、增加页面保存方法
    submitForm(editData) {
      //调用前端校验
     this.editFormVisible=false
    },
    // 删除公司
    deleteUser(index, row) {
      this.$confirm("确定要删除吗?", "信息", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          console.log(row);

          //deptDelete(row.deptId)
          this.$axios
            .get(this.url+"deleteByComplaintsId/" + row.complaintsId)
            .then((response) => {
              if (response.data.code === 200) {
                this.$message({
                  type: "success",
                  message: "已删除!",
                });
                //重新获取列表数据
                this.getdata(this.formInline);
              } else {
                this.$message({
                  type: "info",
                  message: res.data.message,
                });
              }
            })
            .catch((err) => {
              this.loading = false;
              this.$message.error("删除失败，请稍后再试！");
            });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除",
          });
        });
    },
    // 关闭编辑、增加弹出框
    closeDialog() {
      this.editFormVisible = false;
    },
    add(){
        this.$router.push({ path: '/complaint/addBusiness' })
    },
    manage(){
         this.$router.push({ path: '/complaint/business' })
    }
  },
};
</script>

<style scoped>
.user-search {
  margin-top: 20px;
}
.userRole {
  width: 100%;
}
</style>

 
 